package sz.szsmk.citizencard.ui.adapter;

import android.graphics.Color;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.SuggestItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.SuggestMsgRes;
import sz.szsmk.citizencard.ui.activity.SuggestActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/9 22:33
 * description:
 */
public class SuggestAdapter extends RecyclerView.Adapter<SuggestAdapter.SuggestHolder> {
    private SuggestActivity mContext;
    private List<SuggestMsgRes.FeedbackListBean> itemData;

    public SuggestAdapter(SuggestActivity suggestActivity) {
        mContext = suggestActivity;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.suggest_item;
    }

    @Override
    public SuggestHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return SuggestHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(SuggestHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(int position, SuggestItemBinding binding) {
        if (itemData != null) {
            SuggestMsgRes.FeedbackListBean listBean = itemData.get(position);

            binding.ssuggestTime.setText(listBean.getQuestion_time());
            binding.suggestItemTitle.setText(listBean.getQuestion_content());
            int has_answer = listBean.getHas_answer();
            if (has_answer == 0) {
                binding.suggestItemReplay.setText("未回复");
            } else {
                binding.suggestItemReplay.setText("已回复");
                binding.suggestItemReplay.setTextColor(Color.parseColor("#00aaff"));
                binding.suggestAnswer.setText(listBean.getAnswer_content());
            }
        }
    }

    @Override
    public int getItemCount() {
        return null == itemData ? 0 : itemData.size();
    }

    public void setItemData(List<SuggestMsgRes.FeedbackListBean> itemData) {
        this.itemData = itemData;
    }

    public static class SuggestHolder extends RecyclerView.ViewHolder {

        private SuggestItemBinding binding;

        public static SuggestHolder creat(ViewGroup parent) {
            SuggestItemBinding binding = SuggestItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new SuggestHolder(binding);
        }

        public SuggestHolder(SuggestItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
